package com.fxw.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.fxw.data.Result;
import com.fxw.em.ConstantEnum;
import com.fxw.entity.TbPlayer;
import com.fxw.service.ITbPlayerService;
import com.fxw.service.impl.TbPlayerServiceImpl;
import io.swagger.annotations.*;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fxw
 * @since 2021-11-09
 */
@RestController
@RequestMapping("/tb-player")
@Api(value = "选手")
public class TbPlayerController {

    @Autowired
    private ITbPlayerService playerService;

    @ApiOperation("查询所有选手")
    @GetMapping
    public Result getAllPlayers(){
        List<TbPlayer> playerList = playerService.selectAll();
        return Result.bulid(ConstantEnum.SUCCESS).setResult(playerList);
    }

    @ApiOperation("增加选手")
    @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query")
    @PostMapping
    public Result addPlayer(TbPlayer player){
        Boolean aBoolean = playerService.addPlayer(player);
        if (aBoolean){
            return Result.bulid(ConstantEnum.SUCCESS);
        }else{
            return Result.bulid(ConstantEnum.ERROR);
        }

    }
}
